package com.dgut.dao;

import com.dgut.pojo.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface UserDao extends JpaRepository<User,Long> {
    User findByName(String name);
    User findUserById(Long id);

    /**
     * 分页
     * @param pageable
     * @return
     */
    @Query(value = "SELECT * FROM springboot.user WHERE id NOT IN(SELECT id FROM springboot.record WHERE to_days(time) = to_days(now()))",nativeQuery = true)
    Page<User> findUserByNoRecord(Pageable pageable);
    @Query(value = "SELECT * FROM springboot.user where id in (SELECT id FROM springboot.record where to_days(now()) - to_days(time)<=3 and temperature>36.7)",nativeQuery = true)
    Page<User> findUserByOverTemperature(Pageable pageable);
    @Query(value = "SELECT * FROM springboot.user where id in (SELECT id FROM springboot.record where to_days(now()) - to_days(time)<=3 and contact>0)",nativeQuery = true)
    Page<User> findUserByOverContact(Pageable pageable);
    @Query(value = "SELECT * FROM springboot.user where id in (SELECT id FROM springboot.record where to_days(now()) - to_days(time)<=3 and journey>0)",nativeQuery = true)
    Page<User> findUserByOverJourney(Pageable pageable);
}
